{% extends "share/bare_base.html" %}
{% block imports %}
    <script src="statics/scripts/form.js"></script>
    <link rel="stylesheet" href="statics/styles/form.css">
{% endblock %}
{% block main %}
<div class="main-content-container container-fluid px-4">
    {% include "share/main_header.html" %}
    <div class="row">
        <div class="col-lg-6 m-auto">
            <div class="card card-small mb-4">
                <div class="card-header border-bottom">
                    <h6 class="m-0" id="msg">登录</h6>
                </div>
                <ul class="list-group list-group-flush">
                    <li class="list-group-item p-3">
                        <div class="row">
                            <div class="col">
                                <form method="POST" onsubmit="return checkForm()">
                                    <div class="form-row">
                                        <div hidden class="form-group col-md-6 col-lg-12">
                                            <label for="username" class="addRedStar">用户名</label>
                                            <input type="text" class="form-control"
                                                   id="username"
                                                   name="username"
                                                   placeholder="username"
                                                   value="">
                                        </div>
                                        <div class="form-group col-md-6 col-lg-12">
                                            <label for="password" class="addRedStar">密码</label>
                                            <input type="password" class="form-control"
                                                   id="password"
                                                   name="password"
                                                   placeholder="password"
                                                   value="">
                                        </div>
                                        <input type="hidden" id="next" name="next" value="">
                                    </div>
                                    <div class="form-row">
                                        <button type="submit" class="btn btn-accent">登录</button>
                                        <span hidden class="btn btn-accent"
                                              onclick="window.location.href='/accounts/registry/'">注册</span>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </li>
                </ul>
            </div>
        </div>
    </div>
</div>
{% endblock %}
{% block afterload %}
    <script type="text/javascript">
        $(document).ready(function () {
            const queryString = window.location.search;
            const urlParams = new URLSearchParams(queryString);
            if (urlParams.has("next")) {
                $("#next").val(urlParams.get("next"))
            }
        });

        function checkUsername() {
            if ($("#username").val().length === 0) {
                set_msg("用户名不能为空");
                return false;
            }
        }

        function checkForm() {
            cleanErrorMsg();
            let check_result = true;
            // if (!checkText("username")) check_result = false;
            if (!checkText("password")) check_result = false;
            return check_result;
        }

    </script>
{% endblock %}